﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Windows.Forms;

public partial class houtai_login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (txtAdmin.Text.Trim() == "" || txtPwd.Text.Trim() == "")
        {
            MessageBox.Show("用户名或密码不能为空！");
            txtAdmin.Focus();
            return;
        }
        string connString = @"Data Source=.;Initial Catalog=HotelManagement;Integrated Security=True";
        string sql = string.Format("select * from [admin] where adminName='{0}' and adminPwd='{1}'", txtAdmin.Text.Trim(), txtPwd.Text.Trim());
        using (SqlConnection conn = new SqlConnection(connString))
        {
            SqlCommand cmd = new SqlCommand(sql, conn);
            conn.Open();
            SqlDataReader sdr = cmd.ExecuteReader();
            if (sdr.Read())
            {             
                    MessageBox.Show("登录成功");
                    Session["adminName"] = txtAdmin.Text.Trim();    // 把用户名存储到Session变量中
                    Response.Redirect("houtai_index.aspx");
            }
            else
            {
                MessageBox.Show("用户名或密码错误，请重新输入！", "错误");
                txtAdmin.Text = "";
                txtPwd.Text = "";
                txtAdmin.Focus();
            }
            sdr.Close();
        }
    }

   
}